<?php
// This file is part of Meta AGM grading method - https://code.google.com/p/oasychev-moodle-plugins
//
// Meta AGM grading method is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Meta AGM is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Meta AGM.  If not, see <http://www.gnu.org/licenses/>.

/**
 * Metacriterion 'edit settings' form.
 *
 * @package    gradingform_metaagm
 * @author     Nikita Kalinin <nixorv@gmail.com>
 * @copyright  2014 Oleg Sychev (Volgograd State Technical University) <oasychev@gmail.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */

namespace gradingform_metaagm\view;

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir . '/formslib.php');

/**
 * Metacriterion 'edit settings' form class.
 *
 * @package    gradingform_metaagm
 * @author     Nikita Kalinin <nixorv@gmail.com>
 * @copyright  2014 Oleg Sychev (Volgograd State Technical University) <oasychev@gmail.com>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class form_metacriterion_settings extends \moodleform {
    
    function definition() {
        $mform = $this->_form;
        
        if (!isset($this->_customdata['methods'])) {
            throw new coding_exception('Available grading methods array wasn\'t passed to settings form.');
        }
        // We don't support Meta AGM inside Meta AGM.
        $methods = $this->_customdata['methods'];
        if (isset($methods['metaagm'])) {
            unset($methods['metaagm']);
        }
        
        $mform->addElement('text', 'name', get_string('metacriterionname', 'gradingform_metaagm'));
        $mform->setType('name', PARAM_TEXT);
        $mform->addRule('name', null, 'required');
        $mform->addHelpButton('name', 'metacriterionname', 'gradingform_metaagm');
        
        $mform->addElement('text', 'weight', get_string('metacriterionweight', 'gradingform_metaagm'), array('size' => '7'));
        $mform->setType('weight', PARAM_FLOAT);
        $mform->setDefault('weight', '1.0');
        $mform->addRule('weight', null, 'required');
        $mform->addHelpButton('weight', 'metacriterionweight', 'gradingform_metaagm');
        
        $mform->addElement('select', 'method', get_string('gradingmethod', 'gradingform_metaagm'), $methods);
        $mform->addRule('method', null, 'required');
        $mform->addHelpButton('method', 'gradingmethod', 'gradingform_metaagm');
        
        $this->add_action_buttons();
    }
}
